<?php
$file_path = $_POST['path'];
	
if (!empty ($file_path)) {	
	$zipFileName = 'structure.zip';
	
//	$zipFolder = sys_get_temp_dir(); // must be writable
	$zipArchive = tempnam(sys_get_temp_dir(), '').'.zip';			
	
	$folders = array();
	if(preg_match('@\n@', $file_path)) {
		$file_path = nl2br($file_path);
		$folders = explode('<br />', $file_path);
	} else {
		$folders = array($file_path);
	}
		
	// Create the Zip
	$zip = new ZipArchive();
	$zip->open($zipArchive, ZipArchive :: CREATE);	
// 	$zip->addEmptyDir($file_path);
 	foreach($folders as $folder) {
 		$zip->addFromString(trim($folder)."/sample.txt", '');	
 	} 	
	$zip->close();

	// Download the Zip
	ob_flush();
	header('Content-Type: application/octet-stream');
	header('Content-Disposition: attachment; filename="' . $zipFileName . '"');
	header('Content-Transfer-Encoding: binary');
	readfile($zipArchive);
	exit;
}
?>
<style>
.even {
	background:white;
}
.odd {
	background:lightgray;
}

textarea, input[type=text] {
	background:white;
	border:1px solid black;
	color:green;
}

.other_options {
	color:gray;
	font-size:12px;
}
</style>
<h1></h1>
<form id="struct" name="struct" method="post" action="#">
<table width="95%" border="0" cellpadding="3" cellspacing="0">
  <tr>
    <td>Folder Name : <input type="submit" value="Download" /></td>
  </tr>
  <tr>
    <td><textarea name="path" cols="70" rows="5" /><?=$_POST['path'];?></textarea><br />
    	<span style="font-size:smaller;color:gray;">e.g: catalog/view/theme/default/image</span></td>
  </tr>
</table>
</form>
